﻿using System;
using System.Collections.Generic;
using System.Text;

namespace PCDoctor.ScanParameters
{
    public class ProblemScanner
    {
        /// <summary>
        /// Событие "просканирована очередная проблема"
        /// </summary>
        public event ScanPrgress ScanProgressed;

        protected virtual void OnScanProgressed(ScanProgressEventArgs e)
        {
            ScanProgressed(this, e);
        }

        /// <summary>
        /// Полное количество проблем по всем пунктам
        /// </summary>
        public int TotalProblems { get; set; }

        /// <summary>
        /// Сканирование проблем по списку параметров
        /// </summary>
        /// <param name="parameters">Список параметров</param>
        public void Scan(List<ScanParameter> parameters)
        {
            TotalProblems = 0;
            int total = parameters.Count;
            int i = 0;
            foreach (ScanParameter sp in parameters)
            {
                i++;
                sp.Scan();
                TotalProblems += sp.ProblemsCount;
                OnScanProgressed(new ScanProgressEventArgs
                {
                    Progress = (float)Math.Round(((double)i / total * 100), 1),
                    Result = sp.Result,
                    ProblemName = sp.Name,
                    ProblemsCount = sp.ProblemsCount
                });
            }
        }
    }

    /// <summary>
    /// Класс аргументов события "Просканирована очередная проблема"
    /// </summary>
    public class ScanProgressEventArgs : EventArgs
    {
        public float Progress { get; set; }
        public ScanResult Result { get; set; }
        public string ProblemName { get; set; }
        public int ProblemsCount { get; set; }
    }

    public delegate void ScanPrgress(object sender, ScanProgressEventArgs e);
}
